package za.ac.wits.elen4010.capturetheflag;

import za.ac.wits.elen4010.capturetheflag.AndroidForgot;
import za.ac.wits.elen4010.capturetheflag.AndroidSignup;
import za.ac.wits.elen4010.capturetheflag.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AndroidLogin extends Activity {
    /** Called when the activity is first created. */
	
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        
    	final EditText un = (EditText) findViewById(R.id.userNameEditText);
    	final EditText psw = (EditText) findViewById(R.id.pswEditText);
        
        final Button signupButton = (Button) findViewById(R.id.signupButton);
        signupButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	
            	String unStr = un.getText().toString();
            	String pswStr = psw.getText().toString();
            	
            	Bundle b = new Bundle();
            	b.putString("un", unStr);
            	b.putString("psw", pswStr);
            	
                Intent sIntent = new Intent(v.getContext(), AndroidSignup.class);
            	sIntent.putExtras(b);
            	startActivityForResult(sIntent, 0);
            }
        });
        
        final Button loginButton = (Button) findViewById(R.id.loginButton);
        loginButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Perform action on click   
            	 
            	 if (un.getText().toString().isEmpty())
            	 {
            		 Toast.makeText(AndroidLogin.this, "User name invalid", Toast.LENGTH_SHORT).show();
            		 return;
            	 }
            	 if (psw.getText().toString().length() < 5)
            	 {
            		 Toast.makeText(AndroidLogin.this, "Password invalid", Toast.LENGTH_SHORT).show();
            		 return;
            	 }
             	
                 Intent myIntent = new Intent(v.getContext(), Choices.class);
                 startActivityForResult(myIntent, 0); 
            	 Toast.makeText(AndroidLogin.this, "Login Selected", Toast.LENGTH_SHORT).show();           	
             }
         });
        
       final Button forgotButton = (Button) findViewById(R.id.forgotButton);
       forgotButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click 
                Intent myIntent = new Intent(v.getContext(), AndroidForgot.class);
                startActivityForResult(myIntent, 0); 
            }
        });   
       

       
    }

}